<template>
	<view class="container">
		<view class="header">
			<text>选择楼栋</text>
			<!-- <view class="button" @click="skip">跳过</view> -->
		</view>
		<view class="city-info">
			<view class="current selected-city">{{ params.projectName || '' }}</view>
		</view>
		<view class="body">
			<view class="list">
				<view v-for="(item, index) in list" :key="index" @click="toPage(item)" class="list-item">
					<text>{{ item.bn || '' }}</text>
				</view>
			</view>
		</view>
		<loading ref="loading"></loading>
	</view>
</template>

<script>
import http, { customUrl } from '@/common/request.js';
import Loading from '@/components/notice/loading.vue';
import { mapState, mapGetters } from 'vuex';
import { getCommonShareInfo } from '@/common/utils.js';
export default {
	onShareAppMessage() {
		return getCommonShareInfo();
	},
	onLoad(option) {
		this.params = JSON.parse(decodeURIComponent(option.params || '{}'));
	},
	components: {Loading},
	data() {
		return {
			params: {},
		};
	},
	computed: {
		...mapState({ location: state => state.location, list: state => state.houseSetting.buildList }),
	},
	mounted() {
		this.queryList();
	},
	methods: {
		queryList() {
			this.$refs.loading.show();
			http(customUrl.rongchuang + '/member/xcx/member/house/queryRoom', {
				data: {srcYrProjectId: this.params.srcYrProjectId},
				method: 'GET'
			}).then(result => {
				this.$refs.loading.close();
				if(result.success) {
					const list = result.data || [];
					this.$store.dispatch('houseSetting/updateBuildList', list);
				}
			});
		},
		toPage({ bn: buildName, bi: buildId, ul }) {
			this.$store.dispatch('houseSetting/updateUnitList', ul);
			uni.navigateTo({
				url: './unit?params=' + encodeURIComponent(JSON.stringify({ ...this.params, buildName, buildId })),
				animationDuration: 200,
				animationType: 'pop-in'
			});
		},
		skip() {
			uni.navigateBack({
				delta: 2,
				animationDuration: 200,
				animationType: 'pop-out'
			});
		}
	}
};
</script>

<style lang="less" scoped>
@import './house.less';
</style>
